//
//  ViewController.m
//  UIScrollView-山水图
//
//  Created by student on 16/2/29.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIPageControl *pageControl;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    UIImageView *imageView1=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 420, 200)];
//    imageView1.image=[UIImage imageNamed:@"1.jpeg"];
//    
//    UIImageView *imageView2=[[UIImageView alloc]initWithFrame:CGRectMake(420, 0, 420, 200)];
//    imageView2.image=[UIImage imageNamed:@"2.jpeg"];
//    UIImageView *imageView3=[[UIImageView alloc]initWithFrame:CGRectMake(420*2, 0, 420, 200)];
//    imageView3.image=[UIImage imageNamed:@"3.jpeg"];
//    
//    UIImageView *imageView4=[[UIImageView alloc]initWithFrame:CGRectMake(420*3, 0, 420, 200)];
//    imageView4.image=[UIImage imageNamed:@"4.jpeg"];
//    
//    UIImageView *imageView5=[[UIImageView alloc]initWithFrame:CGRectMake(420*4, 0, 420, 200)];
//    imageView5.image=[UIImage imageNamed:@"5.jpeg"];
//    
//    UIImageView *imageView6=[[UIImageView alloc]initWithFrame:CGRectMake(420*5, 0, 420, 200)];
//    imageView6.image=[UIImage imageNamed:@"6.jpeg"];
//
    for (int i=0; i<6; i++) {
        UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(420*i, 0, 420, 200)];
        imageView.image=[UIImage imageNamed:[NSString stringWithFormat:@"%i.jpeg",i+1]];
        
    }

    
    
    UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 420, 200)];
    scrollView.pagingEnabled = YES;
//    [scrollView addSubview:imageView1];
//    [scrollView addSubview:imageView2];
//    [scrollView addSubview:imageView3];
//    [scrollView addSubview:imageView4];
//    [scrollView addSubview:imageView5];
//    [scrollView addSubview:imageView6];
    
    scrollView.contentSize=CGSizeMake(420*6, 0);
    [self.view addSubview:scrollView];
    
    scrollView.delegate=self;
    [self.view addSubview:self.pageControl];
    self.pageControl.numberOfPages=6;
    self.pageControl.currentPage=0;
    self.pageControl.pageIndicatorTintColor=[UIColor redColor];
    self.pageControl.currentPageIndicatorTintColor=[UIColor grayColor];
    

    
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    self.pageControl.currentPage=scrollView.contentOffset.x/420;
}

@end
